package com.example.xuanke.controller;

import com.example.xuanke.pojo.Result;
import com.example.xuanke.pojo.Xuanke;
import com.example.xuanke.service.XuankeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Xxuanke")
public class XuankeController {
    @Autowired
    private XuankeService xuankeService;

    @GetMapping
    public Result getAll(){
        List<Xuanke> xuankes = xuankeService.getAll();
        return Result.success("获取选课信息成功",xuankes);
    }

    @PostMapping
    public Result add(@RequestBody Xuanke xuanke){
        xuankeService.add(xuanke);
        return Result.success("添加选课信息成功",xuanke);
    }

    @PutMapping
    public Result update(@RequestBody Xuanke xuanke){
        xuankeService.update(xuanke);
        return Result.success("修改选课信息成功",xuanke);
    }

    @DeleteMapping
    public Result delete(Integer id){
        xuankeService.delete(id);
        return Result.success("删除选课信息成功",id);
    }
}
